// import Cookies from 'js-cookie'

const TokenKey = 'userInfo';

export const LANGKEY = "locale";

export function getToken(app) {
  let token = null;
  if(process.client&&window.$nuxt&&window.$nuxt.$cookies){
    token = window.$nuxt.$cookies.get(TokenKey);
    window.$nuxt.$store.commit("user/SET_TOKEN", token);
  }
  if(process.server&&app){
    token = app.$cookies.get(TokenKey);
  }
  return token;
}

export function setToken(token, app) {
  if(process.client&&window.$nuxt&&window.$nuxt.$cookies){
    window.$nuxt.$cookies.set(TokenKey, token);
  }
  if(process.server&&app){
    app.$cookies.set(TokenKey, token);
  }
}

export function removeToken(app) {
  if(process.client&&window.$nuxt&&window.$nuxt.$cookies){
    window.$nuxt.$cookies.remove(TokenKey);
  }
  if(process.server&&app){
    app.$cookies.remove(TokenKey);
  }
}

export function getLocalStorage(keyName, app) {
  let lang = null;
  if(process.client&&window.$nuxt&&window.$nuxt.$cookies){
    lang = window.$nuxt.$cookies.get(keyName);
  }
  if(process.server&&app){
    lang = app.$cookies.get(keyName);
  }
  return lang;
}

export function setLocalStorage(keyName, keyValue, app) {
  if(process.client&&window.$nuxt&&window.$nuxt.$cookies){
    window.$nuxt.$cookies.set(keyName, keyValue);
  }
  if(process.server&&app){
    app.$cookies.set(keyName, keyValue);
  }
}

